﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BLL;
using Vews;
using Models;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;


namespace Xingyungou.XiangMing
{
    public partial class 历史纪录 : System.Web.UI.Page
    {
        public List<Employee> listModel { get; set; }
        public string ShowNavPage { get; set; }
        protected void Page_Load(object sender, EventArgs e)
        {

            this.Repeater1.DataSource = HistoryBLL.SelectShopping();
            this.Repeater1.DataBind();


            int total;
            //如果get没有传递pageIndex，则默认显示第一页
            int pageIndex = Request.QueryString["pageIndex"] == null ? 1 : int.Parse(Request.QueryString["pageIndex"]);
            int pageSize = 5;//设置每页显示10行
            listModel = LoadDataByPage(pageIndex, pageSize, out total);
            ShowNavPage = Pager.ShowPageNavigate(pageSize, pageIndex, total);
           
        }
        private List<Employee> LoadDataByPage(int pageIndex, int pageSize, out int total)
        {
            SqlParameter totalPara = new SqlParameter("@total", SqlDbType.Int);
            DataSet ds = new DataSet();
            string connStr = "Data Source=.;Initial Catalog=EmployeeDB;Integrated Security=True";
            //string connStr=ConfigurationManager.ConnectionStrings["sql"].ConnectionString;
            using (SqlConnection conn = new SqlConnection(connStr))
            {
                conn.Open();

                //PR_LoadPageData:存储过程
                using (SqlDataAdapter da = new SqlDataAdapter("PR_LoadPageData", conn))
                {
                    //设置执行类型是存储过程
                    da.SelectCommand.CommandType = CommandType.StoredProcedure;
                    da.SelectCommand.Parameters.AddWithValue("@pageSize", pageSize);
                    da.SelectCommand.Parameters.AddWithValue("@pageIndex", pageIndex);
                    totalPara.Direction = ParameterDirection.Output;
                    da.SelectCommand.Parameters.Add(totalPara);
                    da.Fill(ds);
                }
            }
            total = (int)totalPara.Value;
            return DataTableToList(ds.Tables[0]);
        }

        private List<Employee> DataTableToList(DataTable dt)
        {
            List<Employee> modelList = new List<Employee>();
            //int rowsCount = dt.Rows.Count;
            //if (rowsCount > 0)
            //{
            //    Employee model;
            //    for (int n = 0; n < rowsCount; n++)
            //    {
            //        model = new Employee();
            //        if (dt.Rows[n]["Img"] != null && dt.Rows[n]["Img"].ToString() != "")
            //        {
            //            model.Img =dt.Rows[n]["Img"].ToString();
            //        }
            //        if (dt.Rows[n]["Shoppingming"] != null && dt.Rows[n]["Shoppingming"].ToString() != "")
            //        {
            //            model.Shoppingming = dt.Rows[n]["Shoppingming"].ToString();
            //        }
            //        if (dt.Rows[n]["Condition"] != null && dt.Rows[n]["Condition"].ToString() != "")
            //        {
            //            model.Condition = dt.Rows[n]["Condition"].ToString();
            //        }
            //        if (dt.Rows[n]["Yigorenci"] != null && dt.Rows[n]["Yigorenci"].ToString() != "")
            //        {
            //            model.Yigorenci =Convert.ToInt32( dt.Rows[n]["Yigorenci"].ToString());
            //        }
                   
            //        modelList.Add(model);
            //    }
            //}
            return modelList;
        }
    }
}